<?php
class Bank extends Model
{	
	/*
	Determines if a given item_id is an item
	*/
	function exists($item_id)
	{
		$this->db->from('banks');	
		$this->db->where('bank_id',$item_id);
		$query = $this->db->get();
		return ($query->num_rows()==1);
	}
	
	/*
	Preform a search on items
	*/
	function search($search)
	{
		$this->db->from('banks');
		$this->db->like('name', $search); 
		$this->db->order_by("name", "asc");				
		return $this->db->get();	
	}
		
	/*
	Returns all the items
	*/
	function get_all()
	{
		$this->db->from('banks');
		$this->db->order_by("name", "asc");
		return $this->db->get();		
	}
	
	/*
	Gets information about a particular item
	*/
	function get_info($item_id)
	{
		$this->db->from('banks');
		$this->db->where('bank_id',$item_id);
		$query = $this->db->get();
		
		if($query->num_rows()==1)
		{
			return $query->row();
		}
		else
		{
			//Get empty base parent object, as $item_id is NOT an item
			$item_obj=new stdClass();
			
			//Get all the fields from items table
			$fields = $this->db->list_fields('banks');
			
			foreach ($fields as $field)
			{
				$item_obj->$field='';
			}
			
			return $item_obj;
		}
	}
	
	/*
	Gets information about multiple items
	*/
	function get_multiple_info($item_ids)
	{
		$this->db->from('banks');
		$this->db->where_in('bank_id',$item_ids);
		$this->db->order_by("name", "asc");
		return $this->db->get();	
	}
	
	/*
	Inserts or updates a item
	*/
	function save(&$item_data,$item_id=false)
	{		
		if (!$item_id or !$this->exists($item_id))
		{
			if($this->db->insert('banks',$item_data))
			{
				$item_data['item_id']=$this->db->insert_id();
				return true;
			}
			return false;
		}
		
		$this->db->where('bank_id', $item_id);
		return $this->db->update('banks',$item_data);		
	}
	
	/*
	Deletes one item
	*/
	function delete($item_id)
	{
		return $this->db->delete('banks', array('bank_id' => $item_id)); 
	}
	
	/*
	Deletes a list of items
	*/
	function delete_list($item_ids)
	{		
		$this->db->where_in('bank_id',$item_ids);
		return $this->db->delete('banks');		
 	}
}
?>
